package com.testing.splogin.controller;

import com.testing.splogin.dao.Result;
import com.testing.splogin.tools.MysqlUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.regex.Pattern;

/**
 * @Classname LoginController
 * @Description 类型说明
 * @Date 2021/8/3 17:27
 * @Created by 特斯汀Roy
 */
@RestController
public class LoginController {
    public Pattern specialWords=Pattern.compile("[^\\w_\\-]");
    @PostMapping("/Login")
    public Result login(String user,String password){
        if(user==null||password==null){
            return new Result("-1","用户名密码不能为空");
        }
        if(user.length()>16||user.length()<3||password.length()<3||password.length()>16){
            return new Result("-2","用户名密码必须是3到16位");
        }
        if(specialWords.matcher(user).find()||specialWords.matcher(password).find()){
            return new Result("-3","用户名密码不能包含特殊字符");
        }

        MysqlUtils my=new MysqlUtils();
        if (!my.checkLogin(user,password)){
            return  new Result("-4","用户名密码错误");
        }
        Result result=new Result("0","登录成功");
        return result;

    }


}
